﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GolfScoringApplication
{
    public partial class frmGolfer : Form
    {
        private Golfer objGolfer;

        public FormType _FormType
        {
            get {return FormType.Golfer;}
        }

        public frmGolfer()
        {
            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void cmdAddAddress_Click(object sender, EventArgs e)
        {
            Address();
        }

        private void Address()
        {
            frmAddress objAddress = new frmAddress();
            objAddress.LoadFormVariables(this);
            objAddress.ShowDialog(this);
            
        }

        private void cmdAddEmail_Click(object sender, EventArgs e)
        {
            frmEmail objEmail = new frmEmail();
            objEmail.LoadFormVariables(this);
            objEmail.ShowDialog(this);
        }

        private void cmdAddPhone_Click(object sender, EventArgs e)
        {
            frmPhone objPhone = new frmPhone();
            objPhone.LoadFormVariables(this);
            objPhone.ShowDialog();
        }

        public void AddressAdd(Address newAddress)
        {
            //Add all of the Address Properties here.
            //Console.WriteLine(newAddress.Name);

            int intNewRow = dgAddresses.Rows.Add();
            //Now add the values.

            dgAddresses[1, intNewRow].Value = newAddress.Name;
            dgAddresses[2, intNewRow].Value = newAddress.AddressOne;
            dgAddresses[3, intNewRow].Value = newAddress.AddressTwo;
            dgAddresses[4, intNewRow].Value = newAddress.AddressThree;
            dgAddresses[5, intNewRow].Value = newAddress.City;
            dgAddresses[6, intNewRow].Value = newAddress.State;
            dgAddresses[7, intNewRow].Value = newAddress.ZipCode;
            dgAddresses[0, intNewRow].Value = newAddress.Type.ToString();
        }

        public void AddEmail(EmailAddress newEmail)
        {
            int intNewRow = dgEmailAddresses.Rows.Add();
            dgEmailAddresses[0, intNewRow].Value = newEmail.Type;
            dgEmailAddresses[1, intNewRow].Value = newEmail.Email;
        }

        public void AddPhone(PhoneNumber newPhoneNumber)
        {
            int intNewRow = dgPhoneNumbers.Rows.Add();
            dgPhoneNumbers[0, intNewRow].Value = newPhoneNumber.Type;
            dgPhoneNumbers[1, intNewRow].Value = newPhoneNumber.Number;
            
        }

        private void cmdSave_Click(object sender, EventArgs e)
        {
            //So now load the Golfer class and then save it to the database.
            UpdateGolfer();
            SaveGolfer();
        }

        private void UpdateGolfer()
        {
            //This loops through the form and re-populates the Golfer object.
            //it does not get saved until Save is clicked.

        }

        private void SaveGolfer()
        {
            objGolfer.Save();
        }

    }
}
